home *** CD-ROM | disk | FTP | other *** search
/ CD BIT 75 / CD BIT 75.iso / Software / mysql-4.0.22-win / data1.cab / Development / sql-bench / test-insert < prev    next >
Encoding:
Text File  |  2004-10-28  |  48.1 KB  |  1,751 lines

  1. #!/usr/bin/perl
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # Test of creating a simple table and inserting $record_count records in it,
  20. # $opt_loop_count rows in order, $opt_loop_count rows in reverse order and
  21. # $opt_loop_count rows in random order
  22. #
  23. # changes made for Oracle compatibility
  24. # - $limits->{'func_odbc_mod'} is OK from crash-me, but it fails here so set we
  25. #   set it to 0 in server-cfg
  26. # - the default server config runs out of rollback segments, so we added a
  27. #   couple of disconnect/connects to reset
  28. #
  29. ##################### Standard benchmark inits ##############################
  30.  
  31. use Cwd;
  32. use DBI;
  33. use Benchmark;
  34. use Data::Dumper;
  35.  
  36. $opt_loop_count=100000;        # number of rows/3
  37. $small_loop_count=10;        # Loop for full table retrieval
  38. $range_loop_count=$small_loop_count*50;
  39. $many_keys_loop_count=$opt_loop_count;
  40. $opt_read_key_loop_count=$opt_loop_count;
  41.  
  42. $pwd = cwd(); $pwd = "." if ($pwd eq '');
  43. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  44.  
  45. if ($opt_small_test)
  46. {
  47.   $opt_loop_count/=100;
  48.   $many_keys_loop_count=$opt_loop_count/10;
  49.   $range_loop_count=10;
  50.   $opt_read_key_loop_count=10;
  51. }
  52. elsif ($opt_small_tables)
  53. {
  54.   $opt_loop_count=10000;        # number of rows/3
  55.   $many_keys_loop_count=$opt_loop_count;
  56.   $opt_read_key_loop_count=10;
  57. }
  58. elsif ($opt_small_key_tables)
  59. {
  60.   $many_keys_loop_count/=10;
  61. }
  62.  
  63. if ($opt_loop_count < 100)
  64. {
  65.   $opt_loop_count=100;        # Some tests must have some data to work!
  66. }
  67. $range_loop_count=min($opt_loop_count,$range_loop_count);
  68.  
  69.  
  70. print "Testing the speed of inserting data into 1 table and do some selects on it.\n";
  71. print "The tests are done with a table that has $opt_loop_count rows.\n\n";
  72.  
  73. ####
  74. #### Generating random keys
  75. ####
  76.  
  77. print "Generating random keys\n";
  78. $random[$opt_loop_count]=0;
  79. for ($i=0 ; $i < $opt_loop_count ; $i++)
  80. {
  81.   $random[$i]=$i+$opt_loop_count;
  82. }
  83.  
  84. my $tmpvar=1;
  85. for ($i=0 ; $i < $opt_loop_count ; $i++)
  86. {
  87.   $tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
  88.   $swap=$tmpvar % $opt_loop_count;
  89.   $tmp=$random[$i]; $random[$i]=$random[$swap]; $random[$swap]=$tmp;
  90. }
  91.  
  92. $total_rows=$opt_loop_count*3;
  93.  
  94. ####
  95. ####  Connect and start timeing
  96. ####
  97. $start_time=new Benchmark;
  98. $dbh = $server->connect();
  99. ####
  100. #### Create needed tables
  101. ####
  102.  
  103. goto keys_test if ($opt_stage == 2);
  104. goto select_test if ($opt_skip_create);
  105.  
  106. print "Creating tables\n";
  107. $dbh->do("drop table bench1" . $server->{'drop_attr'});
  108. $dbh->do("drop table bench2" . $server->{'drop_attr'});
  109. $dbh->do("drop table bench3" . $server->{'drop_attr'});
  110. do_many($dbh,$server->create("bench1",
  111.                  ["id int NOT NULL",
  112.                   "id2 int NOT NULL",
  113.                   "id3 int NOT NULL",
  114.                   "dummy1 char(30)"],
  115.                  ["primary key (id,id2)",
  116.                  "index ix_id3 (id3)"]));
  117.  
  118. if ($opt_lock_tables)
  119. {
  120.   $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  121. }
  122.  
  123. ####
  124. #### Insert $total_rows records in order, in reverse order and random.
  125. ####
  126.  
  127. $loop_time=new Benchmark;
  128.  
  129. if ($opt_fast_insert)
  130. {
  131.   $query="insert into bench1 values ";
  132. }
  133. else
  134. {
  135.   $query="insert into bench1 (id,id2,id3,dummy1) values ";
  136. }
  137.  
  138. if ($opt_fast && $server->{transactions})
  139. {
  140.   $dbh->{AutoCommit} = 0;
  141.   print "Transactions enabled\n" if ($opt_debug);
  142. }
  143.  
  144. if (($opt_fast || $opt_fast_insert) && $server->{'limits'}->{'insert_multi_value'})
  145. {
  146.   $query_size=$server->{'limits'}->{'query_size'};
  147.  
  148.   print "Inserting $opt_loop_count multiple-value rows in order\n";
  149.   $res=$query;
  150.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  151.   {
  152.     $tmp= "($i,$i,$i,'ABCDEFGHIJ'),";
  153.     if (length($tmp)+length($res) < $query_size)
  154.     {
  155.       $res.= $tmp;
  156.     }
  157.     else
  158.     {
  159.       $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
  160.       $res=$query . $tmp;
  161.     }
  162.   }
  163.   print "Inserting $opt_loop_count multiple-value rows in reverse order\n";
  164.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  165.   {
  166.     $tmp= "(" . ($total_rows-1-$i) . "," .($total_rows-1-$i) .
  167.       "," .($total_rows-1-$i) . ",'BCDEFGHIJK'),";
  168.     if (length($tmp)+length($res) < $query_size)
  169.     {
  170.       $res.= $tmp;
  171.     }
  172.     else
  173.     {
  174.       $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
  175.       $res=$query . $tmp;
  176.     }
  177.   }
  178.   print "Inserting $opt_loop_count multiple-value rows in random order\n";
  179.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  180.   {
  181.     $tmp= "(" . $random[$i] . "," . $random[$i] . "," . $random[$i] .
  182.       ",'CDEFGHIJKL')," or die $DBI::errstr;
  183.     if (length($tmp)+length($res) < $query_size)
  184.     {
  185.       $res.= $tmp;
  186.     }
  187.     else
  188.     {
  189.       $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
  190.       $res=$query . $tmp;
  191.     }
  192.   }
  193.   $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
  194. }
  195. else
  196. {
  197.   print "Inserting $opt_loop_count rows in order\n";
  198.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  199.   {
  200.     $sth = $dbh->do($query . "($i,$i,$i,'ABCDEFGHIJ')") or die $DBI::errstr;
  201.   }
  202.  
  203.   print "Inserting $opt_loop_count rows in reverse order\n";
  204.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  205.   {
  206.     $sth = $dbh->do($query . "(" . ($total_rows-1-$i) . "," .
  207.             ($total_rows-1-$i) . "," .
  208.             ($total_rows-1-$i) . ",'BCDEFGHIJK')")
  209.       or die $DBI::errstr;
  210.   }
  211.  
  212.   print "Inserting $opt_loop_count rows in random order\n";
  213.  
  214.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  215.   {
  216.     $sth = $dbh->do($query . "(". $random[$i] . "," . $random[$i] .
  217.             "," . $random[$i] . ",'CDEFGHIJKL')") or die $DBI::errstr;
  218.   }
  219. }
  220.  
  221. if ($opt_fast && $server->{transactions})
  222. {
  223.   $dbh->commit;
  224.   $dbh->{AutoCommit} = 1;
  225. }
  226.  
  227. $end_time=new Benchmark;
  228. print "Time for insert (" . ($total_rows) . "): " .
  229.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  230.  
  231. if ($opt_lock_tables)
  232. {
  233.   $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  234. }
  235. if ($opt_fast && defined($server->{vacuum}))
  236. {
  237.   $server->vacuum(1,\$dbh,"bench1");
  238. }
  239. if ($opt_lock_tables)
  240. {
  241.   $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  242. }
  243.  
  244. ####
  245. #### insert $opt_loop_count records with duplicate id
  246. ####
  247.  
  248. if ($limits->{'unique_index'})
  249. {
  250.   print "Testing insert of duplicates\n";
  251.   $loop_time=new Benchmark;
  252.  
  253.   if ($opt_fast && $server->{transactions})
  254.   {
  255.     $dbh->{AutoCommit} = 0;
  256.   }
  257.  
  258.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  259.   {
  260.     $tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
  261.     $tmp=$tmpvar % ($total_rows);
  262.     $tmpquery = "$query ($tmp,$tmp,2,'D')";
  263.     if ($dbh->do($tmpquery))
  264.     {
  265.       die "Didn't get an error when inserting duplicate record $tmp\n";
  266.     }
  267.   }
  268.   if ($opt_fast && $server->{transactions})
  269.   {
  270.     $dbh->commit;
  271.     $dbh->{AutoCommit} = 1;
  272.   }
  273.  
  274.   $end_time=new Benchmark;
  275.   print "Time for insert_duplicates (" . ($opt_loop_count) . "): " .
  276.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  277. }
  278.  
  279.  
  280. ####
  281. #### Do some selects on the table
  282. ####
  283.  
  284. select_test:
  285.  
  286. print "Retrieving data from the table\n";
  287. $loop_time=new Benchmark;
  288. $error=0;
  289.  
  290. # It's really a small table, so we can try a select on everything
  291.  
  292. $count=0;
  293. for ($i=1 ; $i <= $small_loop_count ; $i++)
  294. {
  295.   if (($found_rows=fetch_all_rows($dbh,"select id from bench1")) !=
  296.       $total_rows)
  297.   {
  298.     if (!$error++)
  299.     {
  300.       print "Warning: Got $found_rows rows when selecting a whole table of " . ($total_rows) . " rows\nContact the database or DBD author!\n";
  301.     }
  302.   }
  303.   $count+=$found_rows;
  304. }
  305.  
  306. $end_time=new Benchmark;
  307. print "Time for select_big ($small_loop_count:$count): " .
  308.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  309.  
  310. #
  311. # Do a lot of different ORDER BY queries
  312. #
  313.  
  314. $loop_time=new Benchmark;
  315. $estimated=$rows=0;
  316. for ($i=1 ; $i <= $small_loop_count ; $i++)
  317. {
  318.   $rows+=fetch_all_rows($dbh,"select id,id2 from bench1 order by id,id2",1);
  319.   $end_time=new Benchmark;
  320.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  321.                      $small_loop_count));
  322. }
  323. if ($estimated)
  324. { print "Estimated time"; }
  325. else
  326. { print "Time"; }
  327. print " for order_by_big_key ($small_loop_count:$rows): " .
  328.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  329.  
  330.  
  331. $loop_time=new Benchmark;
  332. $estimated=$rows=0;
  333. for ($i=1 ; $i <= $small_loop_count ; $i++)
  334. {
  335.   $rows+=fetch_all_rows($dbh,"select id,id2 from bench1 order by id desc, id2 desc",1);
  336.   $end_time=new Benchmark;
  337.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  338.                      $small_loop_count));
  339. }
  340. if ($estimated)
  341. { print "Estimated time"; }
  342. else
  343. { print "Time"; }
  344. print " for order_by_big_key_desc ($small_loop_count:$rows): " .
  345.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  346.  
  347.  
  348. $loop_time=new Benchmark;
  349. $estimated=$rows=0;
  350. for ($i=1 ; $i <= $small_loop_count ; $i++)
  351. {
  352.   $rows+=fetch_all_rows($dbh,"select id from bench1 order by id desc",1);
  353.   $end_time=new Benchmark;
  354.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  355.                      $small_loop_count));
  356. }
  357. if ($estimated)
  358. { print "Estimated time"; }
  359. else
  360. { print "Time"; }
  361. print " for order_by_big_key_prefix ($small_loop_count:$rows): " .
  362.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  363.  
  364.  
  365. $loop_time=new Benchmark;
  366. $estimated=$rows=0;
  367. for ($i=1 ; $i <= $small_loop_count ; $i++)
  368. {
  369.   $rows+=fetch_all_rows($dbh,"select id3 from bench1 order by id3",1);
  370.   $end_time=new Benchmark;
  371.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  372.                      $small_loop_count));
  373. }
  374. if ($estimated)
  375. { print "Estimated time"; }
  376. else
  377. { print "Time"; }
  378. print " for order_by_big_key2 ($small_loop_count:$rows): " .
  379.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  380.  
  381.  
  382. $sel=$limits->{'order_by_unused'} ? "id2" : "*";
  383. $loop_time=new Benchmark;
  384. $estimated=$rows=0;
  385. for ($i=1 ; $i <= $small_loop_count ; $i++)
  386. {
  387.   $rows+=fetch_all_rows($dbh,"select $sel from bench1 order by id3",1);
  388.   $end_time=new Benchmark;
  389.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  390.                      $small_loop_count));
  391. }
  392. if ($estimated)
  393. { print "Estimated time"; }
  394. else
  395. { print "Time"; }
  396. print " for order_by_big_key_diff ($small_loop_count:$rows): " .
  397.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  398.  
  399.  
  400. $sel=$limits->{'order_by_unused'} ? "id" : "*";
  401. $loop_time=new Benchmark;
  402. $estimated=$rows=0;
  403. for ($i=1 ; $i <= $small_loop_count ; $i++)
  404. {
  405.   $rows+=fetch_all_rows($dbh,"select $sel from bench1 order by id2,id3",1);
  406.   $end_time=new Benchmark;
  407.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  408.                      $small_loop_count));
  409. }
  410. if ($estimated)
  411. { print "Estimated time"; }
  412. else
  413. { print "Time"; }
  414. print " for order_by_big ($small_loop_count:$rows): " .
  415.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  416.  
  417.  
  418. $sel=$limits->{'order_by_unused'} ? "dummy1" : "dummy1,id3";
  419. $loop_time=new Benchmark;
  420. $estimated=$rows=0;
  421. for ($i=1 ; $i <= $range_loop_count ; $i++)
  422. {
  423.   $start=$opt_loop_count/$range_loop_count*$i;
  424.   $end=$start+$i;
  425.   $rows+=fetch_all_rows($dbh,"select $sel from bench1 where id>=$start and id <= $end order by id3",1);
  426.   $end_time=new Benchmark;
  427.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  428.                      $range_loop_count));
  429. }
  430. if ($estimated)
  431. { print "Estimated time"; }
  432. else
  433. { print "Time"; }
  434. print " for order_by_range ($range_loop_count:$rows): " .
  435.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  436.  
  437. $sel=$limits->{'order_by_unused'} ? "dummy1" : "dummy1,id";
  438. $loop_time=new Benchmark;
  439. $estimated=$rows=0;
  440. for ($i=1 ; $i <= $range_loop_count ; $i++)
  441. {
  442.   $start=$opt_loop_count/$range_loop_count*$i;
  443.   $end=$start+$i;
  444.   $rows+=fetch_all_rows($dbh,"select $sel from bench1 where id>=$start and id <= $end order by id",1);
  445.   $end_time=new Benchmark;
  446.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  447.                      $range_loop_count));
  448. }
  449. if ($estimated)
  450. { print "Estimated time"; }
  451. else
  452. { print "Time"; }
  453. print " for order_by_key_prefix ($range_loop_count:$rows): " .
  454.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  455.  
  456. $sel=$limits->{'order_by_unused'} ? "id2" : "id2,id3";
  457. $loop_time=new Benchmark;
  458. $estimated=$rows=0;
  459. for ($i=1 ; $i <= $range_loop_count ; $i++)
  460. {
  461.   $start=$opt_loop_count/$range_loop_count*$i;
  462.   $end=$start+$range_loop_count;
  463.   $rows+=fetch_all_rows($dbh,"select $sel from bench1 where id3>=$start and id3 <= $end order by id3",1);
  464.   $end_time=new Benchmark;
  465.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$i,
  466.                      $range_loop_count));
  467. }
  468. if ($estimated)
  469. { print "Estimated time"; }
  470. else
  471. { print "Time"; }
  472. print " for order_by_key2_diff ($range_loop_count:$rows): " .
  473.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  474.  
  475. #
  476. # Test of select on 2 different keys with or
  477. # (In this case database can only use keys if they do an automatic union).
  478. #
  479.  
  480. $loop_time=new Benchmark;
  481. $estimated=0;
  482. $rows=0;
  483. $count=0;
  484. for ($i=1 ; $i <= $range_loop_count ; $i++)
  485. {
  486.   my $rnd=$i;
  487.   my $rnd2=$random[$i];
  488.   $rows+=fetch_all_rows($dbh,"select id2 from bench1 where id=$rnd or id3=$rnd2",1);
  489.   $count++;
  490.   $end_time=new Benchmark;
  491.   last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$count,
  492.                      $range_loop_count));
  493. }
  494. if ($estimated)
  495. { print "Estimated time"; }
  496. else
  497. { print "Time"; }
  498. print " for select_diff_key ($count:$rows): " .
  499.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  500.  
  501.  
  502. # Test select that is very popular when using ODBC
  503.  
  504. check_or_range("id","select_range_prefix");
  505. check_or_range("id3","select_range_key2");
  506.  
  507. # Check reading on direct key on id and id3
  508.  
  509. check_select_key("*","id","select_key_prefix");
  510. check_select_key2("*","id","id2","select_key");
  511. check_select_key2("id,id2","id","id2","select_key_return_key");
  512. check_select_key("*","id3","select_key2");
  513. check_select_key("id3","id3","select_key2_return_key");
  514. check_select_key("id,id2","id3","select_key2_return_prim");
  515.  
  516. ####
  517. #### A lot of simple selects on ranges
  518. ####
  519.  
  520. @Q=("select * from bench1 where !id!=3 or !id!=2 or !id!=1 or !id!=4 or !id!=16 or !id!=10",
  521.     6,
  522.     "select * from bench1 where !id!>=" . ($total_rows-1) ." or !id!<1",
  523.     2,
  524.     "select * from bench1 where !id!>=1 and !id!<=2",
  525.     2,
  526.     "select * from bench1 where (!id!>=1 and !id!<=2) or (!id!>=1 and !id!<=2)",
  527.     2,
  528.     "select * from bench1 where !id!>=1 and !id!<=10 and !id!<=5",
  529.     5,
  530.     "select * from bench1 where (!id!>0 and !id!<2) or !id!>=" . ($total_rows-1),
  531.     2,
  532.     "select * from bench1 where (!id!>0 and !id!<2) or (!id!>= " . ($opt_loop_count/2) . " and !id! <= " . ($opt_loop_count/2+2) . ") or !id! = " . ($opt_loop_count/2-1),
  533.     5,
  534.     "select * from bench1 where (!id!>=5 and !id!<=10) or (!id!>=1 and !id!<=4)",
  535.     10,
  536.     "select * from bench1 where (!id!=1 or !id!=2) and (!id!=3 or !id!=4)",
  537.     0,
  538.     "select * from bench1 where (!id!=1 or !id!=2) and (!id!=2 or !id!=3)",
  539.     1,
  540.     "select * from bench1 where (!id!=1 or !id!=5 or !id!=20 or !id!=40) and (!id!=1 or !id!>=20 or !id!=4)",
  541.     3,
  542.     "select * from bench1 where ((!id!=1 or !id!=3) or (!id!>1 and !id!<3)) and !id!<=2",
  543.     2,
  544.     "select * from bench1 where (!id! >= 0 and !id! < 4) or (!id! >=4 and !id! < 6)",
  545.     6,
  546.     "select * from bench1 where !id! <= -1 or (!id! >= 0 and !id! <= 5) or (!id! >=4 and !id! < 6) or (!id! >=6 and !id! <=7) or (!id!>7 and !id! <= 8)",
  547.     9,
  548.     "select * from bench1 where (!id!>=1 and !id!<=2 or !id!>=4 and !id!<=5) or (!id!>=0 and !id! <=10)",
  549.     11,
  550.     "select * from bench1 where (!id!>=1 and !id!<=2 or !id!>=4 and !id!<=5) or (!id!>2 and !id! <=10)",
  551.     10,
  552.     "select * from bench1 where (!id!>1 or !id! <1) and !id!<=2",
  553.     2,
  554.     "select * from bench1 where !id! <= 2 and (!id!>1 or !id! <=1)",
  555.     3,
  556.     "select * from bench1 where (!id!>=1 or !id! <1) and !id!<=2",
  557.     3,
  558.     "select * from bench1 where (!id!>=1 or !id! <=2) and !id!<=2",
  559.     3
  560.     );
  561.  
  562. print "\nTest of compares with simple ranges\n";
  563. check_select_range("id","select_range_prefix");
  564. check_select_range("id3","select_range_key2");
  565.  
  566. ####
  567. #### Some group queries
  568. ####
  569.  
  570. if ($limits->{'group_functions'})
  571. {
  572.   $loop_time=new Benchmark;
  573.   $count=1;
  574.  
  575.   $estimated=0;
  576.   for ($tests=0 ; $tests < $small_loop_count ; $tests++)
  577.   {
  578.     $sth=$dbh->prepare($query="select count(*) from bench1") or die $DBI::errstr;
  579.     $sth->execute or die $sth->errstr;
  580.     if (($sth->fetchrow_array)[0] != $total_rows)
  581.     {
  582.       print "Warning: '$query' returned wrong result\n";
  583.     }
  584.     $sth->finish;
  585.  
  586.     # min, max in keys are very normal
  587.     $count+=7;
  588.     fetch_all_rows($dbh,"select min(id) from bench1");
  589.     fetch_all_rows($dbh,"select max(id) from bench1");
  590.     fetch_all_rows($dbh,"select sum(id+0.0) from bench1");
  591.     fetch_all_rows($dbh,"select min(id3),max(id3),sum(id3-0.0) from bench1");
  592.     if ($limits->{'group_func_sql_min_str'})
  593.     {
  594.       fetch_all_rows($dbh,"select min(dummy1),max(dummy1) from bench1");
  595.     }
  596.     $count++;
  597.     $sth=$dbh->prepare($query="select count(*) from bench1 where id >= " .
  598.                ($opt_loop_count*2)) or die $DBI::errstr;
  599.     $sth->execute or die $DBI::errstr;
  600.     if (($sth->fetchrow_array)[0] != $opt_loop_count)
  601.     {
  602.       print "Warning: '$query' returned wrong result\n";
  603.     }
  604.     $sth->finish;
  605.  
  606.     $count++;
  607.     $sth=$dbh->prepare($query="select count(*),sum(id+0.0),min(id),max(id),avg(id-0.0) from bench1") or die $DBI::errstr;
  608.     $sth->execute or die $DBI::errstr;
  609.     @row=$sth->fetchrow_array;
  610.     if ($row[0] != $total_rows ||
  611.     int($row[1]+0.5) != int((($total_rows-1)/2*$total_rows)+0.5) ||
  612.     $row[2] != 0 ||
  613.     $row[3] != $total_rows-1 ||
  614.     1-$row[4]/(($total_rows-1)/2) > 0.001)
  615.     {
  616.       # PostgreSQL 6.3 fails here
  617.       print "Warning: '$query' returned wrong result: @row\n";
  618.     }
  619.     $sth->finish;
  620.  
  621.     if ($limits->{'func_odbc_mod'})
  622.     {
  623.       $tmp="mod(id,10)";
  624.       if ($limits->{'func_extra_%'})
  625.       {
  626.     $tmp="id % 10";        # For postgreSQL
  627.       }
  628.       $count++;
  629.       if ($limits->{'group_by_alias'}) {
  630.     if (fetch_all_rows($dbh,$query=$server->query("select $tmp as last_digit,count(*) from bench1 group by last_digit")) != 10)
  631.     {
  632.       print "Warning: '$query' returned wrong number of rows\n";
  633.     }
  634.       } elsif ($limits->{'group_by_position'}) {
  635.     if (fetch_all_rows($dbh,$query=$server->query("select $tmp,count(*) from bench1 group by 1")) != 10)
  636.     {
  637.       print "Warning: '$query' returned wrong number of rows\n";
  638.     }
  639.       }
  640.     }
  641.  
  642.     if ($limits->{'order_by_position'} && $limits->{'group_by_position'})
  643.     {
  644.       $count++;
  645.       if (fetch_all_rows($dbh, $query="select id,id3,dummy1 from bench1 where id < 100+$count-$count group by id,id3,dummy1 order by id desc,id3,dummy1") != 100)
  646.       {
  647.     print "Warning: '$query' returned wrong number of rows\n";
  648.       }
  649.     }
  650.     $end_time=new Benchmark;
  651.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
  652.                        $small_loop_count));
  653.   }
  654.   print_time($estimated);
  655.   print " for select_group ($count): " .
  656.       timestr(timediff($end_time, $loop_time),"all") . "\n";
  657.  
  658.   $loop_time=new Benchmark;
  659.   $count=$estimated=0;
  660.   for ($tests=1 ; $tests <= $range_loop_count*5 ; $tests++)
  661.   {
  662.     $count+=6;
  663.     fetch_all_rows($dbh,"select min(id) from bench1");
  664.     fetch_all_rows($dbh,"select max(id) from bench1");
  665.     fetch_all_rows($dbh,"select min(id2) from bench1 where id=$tests");
  666.     fetch_all_rows($dbh,"select max(id2) from bench1 where id=$tests");
  667.     if ($limits->{'group_func_sql_min_str'})
  668.     {
  669.       fetch_all_rows($dbh,"select min(dummy1) from bench1 where id=$tests");
  670.       fetch_all_rows($dbh,"select max(dummy1) from bench1 where id=$tests");
  671.     }
  672.     $end_time=new Benchmark;
  673.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
  674.                        $range_loop_count*5));
  675.   }
  676.   if ($estimated)
  677.   { print "Estimated time"; }
  678.   else
  679.   { print "Time"; }
  680.   print " for min_max_on_key ($count): " .
  681.       timestr(timediff($end_time, $loop_time),"all") . "\n";
  682.  
  683.   $loop_time=new Benchmark;
  684.   $count=$estimated=0;
  685.   for ($tests=1 ; $tests <= $small_loop_count ; $tests++)
  686.   {
  687.     $count+=6;
  688.     fetch_all_rows($dbh,"select min(id2) from bench1");
  689.     fetch_all_rows($dbh,"select max(id2) from bench1");
  690.     fetch_all_rows($dbh,"select min(id3) from bench1 where id2=$tests");
  691.     fetch_all_rows($dbh,"select max(id3) from bench1 where id2=$tests");
  692.     if ($limits->{'group_func_sql_min_str'})
  693.     {
  694.       fetch_all_rows($dbh,"select min(dummy1) from bench1 where id2=$tests");
  695.       fetch_all_rows($dbh,"select max(dummy1) from bench1 where id2=$tests");
  696.     }
  697.     $end_time=new Benchmark;
  698.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
  699.                        $range_loop_count));
  700.   }
  701.   if ($estimated)
  702.   { print "Estimated time"; }
  703.   else
  704.   { print "Time"; }
  705.   print " for min_max ($count): " .
  706.       timestr(timediff($end_time, $loop_time),"all") . "\n";
  707.  
  708.   $loop_time=new Benchmark;
  709.   $count=0;
  710.   $total=$opt_loop_count*3;
  711.   for ($tests=0 ; $tests < $total ; $tests+=$total/100)
  712.   {
  713.     $count+=1;
  714.     fetch_all_rows($dbh,"select count(id) from bench1 where id < $tests");
  715.   }
  716.   $end_time=new Benchmark;
  717.   print "Time for count_on_key ($count): " .
  718.       timestr(timediff($end_time, $loop_time),"all") . "\n";
  719.  
  720.   $loop_time=new Benchmark;
  721.   $count=0;
  722.   for ($tests=0 ; $tests < $total ; $tests+=$total/100)
  723.   {
  724.     $count+=1;
  725.     fetch_all_rows($dbh,"select count(dummy1) from bench1 where id2 < $tests");
  726.   }
  727.   $end_time=new Benchmark;
  728.   print "Time for count ($count): " .
  729.       timestr(timediff($end_time, $loop_time),"all") . "\n";
  730.  
  731.   if ($limits->{'group_distinct_functions'})
  732.   {
  733.     $loop_time=new Benchmark;
  734.     $count=$estimated=0;
  735.     for ($tests=1 ; $tests <= $small_loop_count ; $tests++)
  736.     {
  737.       $count+=2;
  738.       fetch_all_rows($dbh,"select count(distinct dummy1) from bench1");
  739.       fetch_all_rows($dbh,"select dummy1,count(distinct id) from bench1 group by dummy1");
  740.       $end_time=new Benchmark;
  741.       last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$tests,
  742.                          $small_loop_count));
  743.     }
  744.     if ($estimated)
  745.     { print "Estimated time"; }
  746.     else
  747.     { print "Time"; }
  748.     print " for count_distinct_big ($count): " .
  749.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  750.   }
  751. }
  752.  
  753.  
  754. if ($server->small_rollback_segment())
  755. {
  756.   $dbh->disconnect;                # close connection
  757.   $dbh = $server->connect();
  758. }
  759.  
  760. ####
  761. #### Some updates on the table
  762. ####
  763.  
  764. $loop_time=new Benchmark;
  765.  
  766. if ($limits->{'functions'})
  767. {
  768.   print "\nTesting update of keys with functions\n";
  769.   my $update_loop_count=$opt_loop_count/2;
  770.   for ($i=0 ; $i < $update_loop_count ; $i++)
  771.   {
  772.     my $tmp=$opt_loop_count+$random[$i]; # $opt_loop_count*2 <= $tmp < $total_rows
  773.     $sth = $dbh->do("update bench1 set id3=-$tmp where id3=$tmp") or die $DBI::errstr;
  774.   }
  775.  
  776.   $end_time=new Benchmark;
  777.   print "Time for update_of_key ($update_loop_count):  " .
  778.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  779.  
  780.   if ($opt_lock_tables)
  781.   {
  782.     do_query($dbh,"UNLOCK TABLES");
  783.   }
  784.   if ($opt_fast && defined($server->{vacuum}))
  785.   {
  786.     $server->vacuum(1,\$dbh,"bench1");
  787.   }
  788.   if ($opt_lock_tables)
  789.   {
  790.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  791.   }
  792.  
  793.   if ($server->small_rollback_segment())
  794.   {
  795.     $dbh->disconnect;                # close connection
  796.     $dbh = $server->connect();
  797.   }
  798.  
  799.   $loop_time=new Benchmark;
  800.   $count=0;
  801.   $step=int($opt_loop_count/$range_loop_count+1);
  802.   for ($i= 0 ; $i < $opt_loop_count ; $i+= $step)
  803.   {
  804.     $count++;
  805.     $sth=$dbh->do("update bench1 set id3= 0-id3 where id3 >= 0 and id3 <= $i") or die $DBI::errstr;
  806.   }
  807.  
  808.   if ($server->small_rollback_segment())
  809.   {
  810.     $dbh->disconnect;                # close connection
  811.     $dbh = $server->connect();
  812.   }
  813.   $count++;
  814.   $sth=$dbh->do("update bench1 set id3= 0-id3 where id3 >= 0 and id3 < $opt_loop_count") or die $DBI::errstr;
  815.  
  816.   if ($server->small_rollback_segment())
  817.   {
  818.     $dbh->disconnect;                # close connection
  819.     $dbh = $server->connect();
  820.   }
  821.   $count++;
  822.   $sth=$dbh->do("update bench1 set id3= 0-id3 where id3 >= $opt_loop_count and id3 < ". ($opt_loop_count*2)) or die $DBI::errstr;
  823.  
  824.   #
  825.   # Check that everything was updated
  826.   # In principle we shouldn't time this in the update loop..
  827.   #
  828.  
  829.   if ($server->small_rollback_segment())
  830.   {
  831.     $dbh->disconnect;                # close connection
  832.     $dbh = $server->connect();
  833.   }
  834.   $row_count=0;
  835.   if (($sth=$dbh->prepare("select count(*) from bench1 where id3>=0"))
  836.       && $sth->execute)
  837.   {
  838.     ($row_count)=$sth->fetchrow;
  839.   }
  840.   $result=1 + $opt_loop_count-$update_loop_count;
  841.   if ($row_count != $result)
  842.   {
  843.     print "Warning: Update check returned $row_count instead of $result\n";
  844.   }
  845.  
  846.   $sth->finish;
  847.   if ($server->small_rollback_segment())
  848.   {
  849.     $dbh->disconnect;                # close connection
  850.     $dbh = $server->connect();
  851.   }
  852.   #restore id3 to 0 <= id3 < $total_rows/10 or 0<= id3 < $total_rows
  853.  
  854.   my $func=($limits->{'func_odbc_floor'}) ? "floor((0-id3)/20)" : "0-id3";
  855.   $count++;
  856.   $sth=$dbh->do($query="update bench1 set id3=$func where id3<0") or die $DBI::errstr;
  857.  
  858.   $end_time=new Benchmark;
  859.   print "Time for update_of_key_big ($count): " .
  860.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  861. }
  862. else
  863. {
  864.   print "\nTesting update of keys in loops\n";
  865.   #
  866.   # This is for mSQL that doesn't have functions. Do we really need this ????
  867.   #
  868.  
  869.   $sth=$dbh->prepare("select id3 from bench1 where id3 >= 0") or die $DBI::errstr;
  870.   $sth->execute or die $DBI::errstr;
  871.   $count=0;
  872.   while (@tmp = $sth->fetchrow_array)
  873.   {
  874.     my $tmp1 = "-$tmp[0]";
  875.     my $sth1 = $dbh->do("update bench1 set id3 = $tmp1 where id3 = $tmp[0]");
  876.     $count++;
  877.     $end_time=new Benchmark;
  878.     if (($end_time->[0] - $loop_time->[0]) > $opt_time_limit)
  879.     {
  880.       print "note: Aborting update loop because of timeout\n";
  881.       last;
  882.     }
  883.   }
  884.   $sth->finish;
  885.   # Check that everything except id3=0 was updated
  886.   # In principle we shouldn't time this in the update loop..
  887.   #
  888.   if (fetch_all_rows($dbh,$query="select * from bench1 where id3>=0") != 1)
  889.   {
  890.     if ($count == $total_rows)
  891.     {
  892.       print "Warning: Wrong information after update: Found '$row_count' rows, but should have been: 1\n";
  893.     }
  894.   }
  895.   #restore id3 to 0 <= id3 < $total_rows
  896.   $sth=$dbh->prepare("select id3 from bench1 where id3 < 0") or die $DBI::errstr;
  897.   $sth->execute or die $DBI::errstr;
  898.   while (@tmp = $sth->fetchrow_array)
  899.   {
  900.     $count++;
  901.     my $tmp1 = floor((0-$tmp[0])/10);
  902.     my $sth1 = $dbh->do("update bench1 set id3 = $tmp1 where id3 = $tmp[0]");
  903.   }
  904.   $sth->finish;
  905.   $end_time=new Benchmark;
  906.   $estimated=predict_query_time($loop_time,$end_time,\$count,$count,
  907.                 $opt_loop_count*6);
  908.   if ($estimated)
  909.   { print "Estimated time"; }
  910.   else
  911.   { print "Time"; }
  912.   print " for update_of_key ($count): " .
  913.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  914. }
  915.  
  916. if ($opt_fast && defined($server->{vacuum}))
  917. {
  918.   if ($opt_lock_tables)
  919.   {
  920.     do_query($dbh,"UNLOCK TABLES");
  921.   }
  922.   $server->vacuum(1,\$dbh,"bench1");
  923.   if ($opt_lock_tables)
  924.   {
  925.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  926.   }
  927. }
  928.  
  929. #
  930. # Testing some simple updates
  931. #
  932.  
  933. print "Testing update with key\n";
  934. $loop_time=new Benchmark;
  935. for ($i=0 ; $i < $opt_loop_count*3 ; $i++)
  936. {
  937.   $sth = $dbh->do("update bench1 set dummy1='updated' where id=$i and id2=$i") or die $DBI::errstr;
  938. }
  939.  
  940. $end_time=new Benchmark;
  941. print "Time for update_with_key (" . ($opt_loop_count*3) . "):  " .
  942.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  943.  
  944. $loop_time=new Benchmark;
  945. $count=0;
  946. for ($i=1 ; $i < $opt_loop_count*3 ; $i+=3)
  947. {
  948.   $sth = $dbh->do("update bench1 set dummy1='updated' where id=$i") or die $DBI::errstr;
  949.   $end_time=new Benchmark;
  950.   last if ($estimated=predict_query_time($loop_time,$end_time,\$i,$tests,
  951.                      $opt_loop_count));
  952. }
  953. if ($estimated)
  954. { print "Estimated time"; }
  955. else
  956. { print "Time"; }
  957. print " for update_with_key_prefix (" . ($opt_loop_count) . "):  " .
  958.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  959.  
  960. print "\nTesting update of all rows\n";
  961. $loop_time=new Benchmark;
  962. for ($i=0 ; $i < $small_loop_count ; $i++)
  963. {
  964.   $sth = $dbh->do("update bench1 set dummy1='updated $i'") or die $DBI::errstr;
  965. }
  966. $end_time=new Benchmark;
  967. print "Time for update_big ($small_loop_count):  " .
  968.   timestr(timediff($end_time, $loop_time),"all") . "\n";
  969.  
  970.  
  971. #
  972. # Testing left outer join
  973. #
  974.  
  975. if ($limits->{'func_odbc_floor'} && $limits->{'left_outer_join'})
  976. {
  977.   if ($opt_lock_tables)
  978.   {
  979.     $sth = $dbh->do("LOCK TABLES bench1 a READ, bench1 b READ") || die $DBI::errstr;
  980.   }
  981.   print "\nTesting left outer join\n";
  982.   $loop_time=new Benchmark;
  983.   $count=0;
  984.   for ($i=0 ; $i < $small_loop_count ; $i++)
  985.   {
  986.     $count+=fetch_all_rows($dbh,"select count(*) from bench1 as a left outer join bench1 as b on (a.id2=b.id3)");
  987.   }
  988.   $end_time=new Benchmark;
  989.   print "Time for outer_join_on_key ($small_loop_count:$count):  " .
  990.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  991.  
  992.   $loop_time=new Benchmark;
  993.   $count=0;
  994.   for ($i=0 ; $i < $small_loop_count ; $i++)
  995.   {
  996.     $count+=fetch_all_rows($dbh,"select count(a.dummy1),count(b.dummy1) from bench1 as a left outer join bench1 as b on (a.id2=b.id3)");
  997.   }
  998.   $end_time=new Benchmark;
  999.   print "Time for outer_join ($small_loop_count:$count):  " .
  1000.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1001.  
  1002.   $count=0;
  1003.   $loop_time=new Benchmark;
  1004.   for ($i=0 ; $i < $small_loop_count ; $i++)
  1005.   {
  1006.     $count+=fetch_all_rows($dbh,"select count(a.dummy1),count(b.dummy1) from bench1 as a left outer join bench1 as b on (a.id2=b.id3) where b.id3 is not null");
  1007.   }
  1008.   $end_time=new Benchmark;
  1009.   print "Time for outer_join_found ($small_loop_count:$count):  " .
  1010.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1011.  
  1012.   $count=$estimated=0;
  1013.   $loop_time=new Benchmark;
  1014.   for ($i=1 ; $i <= $small_loop_count ; $i++)
  1015.   {
  1016.     $count+=fetch_all_rows($dbh,"select count(a.dummy1),count(b.dummy1) from bench1 as a left outer join bench1 as b on (a.id2=b.id3) where b.id3 is null");
  1017.     $end_time=new Benchmark;
  1018.     last if ($estimated=predict_query_time($loop_time,$end_time,
  1019.                        \$count,$i,
  1020.                        $range_loop_count));
  1021.   }
  1022.   if ($estimated)
  1023.   { print "Estimated time"; }
  1024.   else
  1025.   { print "Time"; }
  1026.   print " for outer_join_not_found ($range_loop_count:$count):  " .
  1027.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1028.  
  1029.   if ($opt_lock_tables)
  1030.   {
  1031.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  1032.   }
  1033. }
  1034.  
  1035. if ($server->small_rollback_segment())
  1036. {
  1037.   $dbh->disconnect;                # close connection
  1038.   $dbh = $server->connect();
  1039. }
  1040.  
  1041. ###
  1042. ### Test speed of IN( value list)
  1043. ###
  1044.  
  1045. if ($limits->{'left_outer_join'})
  1046. {
  1047.   if ($opt_lock_tables)
  1048.   {
  1049.     $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  1050.   }
  1051.   print "\n";
  1052.   do_many($dbh,$server->create("bench2",
  1053.                    ["id int NOT NULL"],
  1054.                    ["primary key (id)"]));
  1055.  
  1056.   $max_tests=min(($limits->{'query_size'}-50)/6, $opt_loop_count);
  1057.  
  1058.   if ($opt_lock_tables)
  1059.   {
  1060.     $sth = $dbh->do("LOCK TABLES bench1 READ, bench2 WRITE") ||
  1061.       die $DBI::errstr;
  1062.   }
  1063.   test_where_in("bench1","bench2","id",1,10);
  1064.   test_where_in("bench1","bench2","id",11,min(100,$max_tests));
  1065.   test_where_in("bench1","bench2","id",101,min(1000,$max_tests));
  1066.   if ($opt_lock_tables)
  1067.   {
  1068.     $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  1069.   }
  1070.   $sth = $dbh->do("DROP TABLE bench2" . $server->{'drop_attr'}) ||
  1071.     die $DBI::errstr;
  1072.   if ($opt_lock_tables)
  1073.   {
  1074.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  1075.   }
  1076. }
  1077.  
  1078. ####
  1079. #### Test INSERT INTO ... SELECT
  1080. ####
  1081.  
  1082. if ($limits->{'insert_select'})
  1083. {
  1084.   if ($opt_lock_tables)
  1085.   {
  1086.     $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  1087.   }
  1088.   print "\nTesting INSERT INTO ... SELECT\n";
  1089.   do_many($dbh,$server->create("bench2",
  1090.                    ["id int NOT NULL",
  1091.                 "id2 int NOT NULL",
  1092.                 "id3 int NOT NULL",
  1093.                 "dummy1 char(30)"],
  1094.                    ["primary key (id,id2)"]));
  1095.   do_many($dbh,$server->create("bench3",
  1096.                    ["id int NOT NULL",
  1097.                 "id2 int NOT NULL",
  1098.                 "id3 int NOT NULL",
  1099.                 "dummy1 char(30)"],
  1100.                    ["primary key (id,id2)",
  1101.                 "index index_id3 (id3)"]));
  1102.   $loop_time=new Benchmark;
  1103.   $sth = $dbh->do("INSERT INTO bench2 SELECT * from bench1") ||
  1104.     die $DBI::errstr;
  1105.   $end_time=new Benchmark;
  1106.   print "Time for insert_select_1_key (1):  " .
  1107.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1108.   $loop_time=new Benchmark;
  1109.   $sth = $dbh->do("INSERT INTO bench3 SELECT * from bench1") ||
  1110.     die $DBI::errstr;
  1111.   $end_time=new Benchmark;
  1112.   print "Time for insert_select_2_keys (1):  " .
  1113.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1114.   $loop_time=new Benchmark;
  1115.   $sth = $dbh->do("DROP TABLE bench2" . $server->{'drop_attr'}) ||
  1116.     die $DBI::errstr;
  1117.   $sth = $dbh->do("DROP TABLE bench3" . $server->{'drop_attr'}) ||
  1118.     die $DBI::errstr;
  1119.   $end_time=new Benchmark;
  1120.   print "Time for drop table(2): " .
  1121.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1122.  
  1123.   if ($opt_fast && defined($server->{vacuum}))
  1124.   {
  1125.     $server->vacuum(1,\$dbh);
  1126.   }
  1127.   if ($server->small_rollback_segment())
  1128.   {
  1129.     $dbh->disconnect;                # close connection
  1130.     $dbh = $server->connect();
  1131.   }
  1132.   if ($opt_lock_tables)
  1133.   {
  1134.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  1135.   }
  1136. }
  1137.  
  1138. ####
  1139. #### Do some deletes on the table
  1140. ####
  1141.  
  1142. if (!$opt_skip_delete)
  1143. {
  1144.   print "\nTesting delete\n";
  1145.   $loop_time=new Benchmark;
  1146.   $count=0;
  1147.   for ($i=0 ; $i < $opt_loop_count ; $i+=10)
  1148.   {
  1149.     $count++;
  1150.     $tmp=$opt_loop_count+$random[$i]; # $opt_loop_count*2 <= $tmp < $total_rows
  1151.     $dbh->do("delete from bench1 where id3=$tmp") or die $DBI::errstr;
  1152.   }
  1153.  
  1154.   $end_time=new Benchmark;
  1155.   print "Time for delete_key ($count): " .
  1156.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1157.  
  1158.   if ($server->small_rollback_segment())
  1159.   {
  1160.     $dbh->disconnect;                # close connection
  1161.     $dbh = $server->connect();
  1162.   }
  1163.  
  1164.   $count=0;
  1165.   $loop_time=new Benchmark;
  1166.   for ($i= 0 ; $i < $opt_loop_count ; $i+=$opt_loop_count/10)
  1167.   {
  1168.     $sth=$dbh->do("delete from bench1 where id3 >= 0 and id3 <= $i") or die $DBI::errstr;
  1169.     $count++;
  1170.   }
  1171.   $count+=2;
  1172.   if ($server->small_rollback_segment())
  1173.   {
  1174.     $dbh->disconnect;                # close connection
  1175.     $dbh = $server->connect();
  1176.   }
  1177.   $sth=$dbh->do("delete from bench1 where id3 >= 0 and id3 <= $opt_loop_count") or die $DBI::errstr;
  1178.   if ($server->small_rollback_segment())
  1179.   {
  1180.     $dbh->disconnect;                # close connection
  1181.     $dbh = $server->connect();
  1182.   }
  1183.  
  1184.   $sth=$dbh->do("delete from bench1 where id >= $opt_loop_count and id <= " . ($opt_loop_count*2) ) or die $DBI::errstr;
  1185.  
  1186.   if ($server->small_rollback_segment())
  1187.   {
  1188.     $dbh->disconnect;                # close connection
  1189.     $dbh = $server->connect();
  1190.   }
  1191.   if ($opt_fast)
  1192.   {
  1193.     $sth=$dbh->do("delete from bench1") or die $DBI::errstr;
  1194.   }
  1195.   else
  1196.   {
  1197.     $sth = $dbh->do("delete from bench1 where id3 < " . ($total_rows)) or die $DBI::errstr;
  1198.   }
  1199.  
  1200.   $end_time=new Benchmark;
  1201.   print "Time for delete_range ($count): " .
  1202.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1203.  
  1204.   if ($opt_lock_tables)
  1205.   {
  1206.     $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  1207.   }
  1208.   $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
  1209. }
  1210.  
  1211. if ($server->small_rollback_segment())
  1212. {
  1213.   $dbh->disconnect;                # close connection
  1214.   $dbh = $server->connect();
  1215. }
  1216. if ($opt_fast && defined($server->{vacuum}))
  1217. {
  1218.   $server->vacuum(1,\$dbh);
  1219. }
  1220.  
  1221.  
  1222. keys_test:
  1223. #
  1224. # Test of insert in table with many keys
  1225. # This test assumes that the server really create the keys!
  1226. #
  1227.  
  1228. my @fields=(); my @keys=();
  1229. $keys=min($limits->{'max_index'},16);          # 16 is more than enough
  1230. $seg= min($limits->{'max_index_parts'},$keys,16); # 16 is more than enough
  1231.  
  1232. print "Insert into table with $keys keys and with a primary key with $seg parts\n";
  1233.  
  1234. # Make keys on the most important types
  1235. @types=(0,0,0,1,0,0,0,1,1,1,1,1,1,1,1,1,1);    # A 1 for each char field
  1236. push(@fields,"field1 tinyint not null");
  1237. push(@fields,"field_search tinyint not null");
  1238. push(@fields,"field2 mediumint not null");
  1239. push(@fields,"field3 smallint not null");
  1240. push(@fields,"field4 char(16) not null");
  1241. push(@fields,"field5 integer not null");
  1242. push(@fields,"field6 float not null");
  1243. push(@fields,"field7 double not null");
  1244. for ($i=8 ; $i <= $keys ; $i++)
  1245. {
  1246.   push(@fields,"field$i char(6) not null");    # Should be relatively fair
  1247. }
  1248.  
  1249. # First key contains many segments
  1250. $query="primary key (";
  1251. for ($i= 1 ; $i <= $seg ; $i++)
  1252. {
  1253.   $query.= "field$i,";
  1254. }
  1255. substr($query,-1)=")";
  1256. push (@keys,$query);
  1257. push (@keys,"index index2 (field_search)");
  1258.  
  1259. #Create other keys
  1260. for ($i=3 ; $i <= $keys ; $i++)
  1261. {
  1262.   push(@keys,"index index$i (field$i)");
  1263. }
  1264.  
  1265. do_many($dbh,$server->create("bench1",\@fields,\@keys));
  1266. if ($opt_lock_tables)
  1267. {
  1268.   $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  1269. }
  1270.  
  1271. if ($server->small_rollback_segment())
  1272. {
  1273.   $dbh->disconnect;                # close connection
  1274.   $dbh = $server->connect();
  1275. }
  1276.  
  1277. $loop_time=new Benchmark;
  1278. if ($opt_fast && $server->{transactions})
  1279. {
  1280.   $dbh->{AutoCommit} = 0;
  1281. }
  1282.  
  1283. $fields=$#fields;
  1284. if (($opt_fast || $opt_fast_insert) && $server->{'limits'}->{'insert_multi_value'})
  1285. {
  1286.   $query_size=$server->{'limits'}->{'query_size'};
  1287.   $query="insert into bench1 values ";
  1288.   $res=$query;
  1289.   for ($i=0; $i < $many_keys_loop_count; $i++)
  1290.   {
  1291.     $id= $i & 127;
  1292.     $rand=$random[$i];
  1293.     $tmp="($id,$id,$rand," . ($i & 32766) . ",'ABCDEF$rand',0,$rand,$rand.0,";
  1294.  
  1295.     for ($j=8; $j <= $fields ; $j++)
  1296.     {
  1297.       $tmp.= ($types[$j] == 0) ? "$rand," : "'$rand',";
  1298.     }
  1299.     substr($tmp,-1)=")";
  1300.     if (length($tmp)+length($res) < $query_size)
  1301.     {
  1302.       $res.= $tmp . ",";
  1303.     }
  1304.     else
  1305.     {
  1306.       $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
  1307.       $res=$query . $tmp . ",";
  1308.     }
  1309.   }
  1310.   $sth = $dbh->do(substr($res,0,length($res)-1)) or die $DBI::errstr;
  1311. }
  1312. else
  1313. {
  1314.   for ($i=0; $i < $many_keys_loop_count; $i++)
  1315.   {
  1316.     $id= $i & 127;
  1317.     $rand=$random[$i];
  1318.     $query="insert into bench1 values ($id,$id,$rand," . ($i & 32767) .
  1319.       ",'ABCDEF$rand',0,$rand,$rand.0,";
  1320.  
  1321.     for ($j=8; $j <= $fields ; $j++)
  1322.     {
  1323.       $query.= ($types[$j] == 0) ? "$rand," : "'$rand',";
  1324.     }
  1325.     substr($query,-1)=")";
  1326.     print "query1: $query\n" if ($opt_debug);
  1327.     $dbh->do($query) or die "Got error $DBI::errstr with query: $query\n";
  1328.   }
  1329. }
  1330.  
  1331. if ($opt_fast && $server->{transactions})
  1332. {
  1333.   $dbh->commit;
  1334.   $dbh->{AutoCommit} = 1;
  1335. }
  1336.  
  1337. $end_time=new Benchmark;
  1338. print "Time for insert_key ($many_keys_loop_count): " .
  1339.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1340.  
  1341. if ($server->small_rollback_segment())
  1342. {
  1343.   $dbh->disconnect;                # close connection
  1344.   $dbh = $server->connect();
  1345. }
  1346. if ($opt_fast && defined($server->{vacuum}))
  1347. {
  1348.   if ($opt_lock_tables)
  1349.   {
  1350.     do_query($dbh,"UNLOCK TABLES");
  1351.   }
  1352.   $server->vacuum(1,\$dbh,"bench1");
  1353.   if ($opt_lock_tables)
  1354.   {
  1355.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  1356.   }
  1357. }
  1358.  
  1359. #
  1360. # update one key of the above
  1361. #
  1362.  
  1363. print "Testing update of keys\n";
  1364. $loop_time=new Benchmark;
  1365.  
  1366. if ($opt_fast && $server->{transactions})
  1367. {
  1368.   $dbh->{AutoCommit} = 0;
  1369. }
  1370.  
  1371. for ($i=0 ; $i< 256; $i++)
  1372. {
  1373.   $dbh->do("update bench1 set field5=1 where field_search=$i")
  1374.     or die "Got error $DBI::errstr with query: update bench1 set field5=1 where field_search=$i\n";
  1375. }
  1376.  
  1377. if ($opt_fast && $server->{transactions})
  1378. {
  1379.   $dbh->commit;
  1380.   $dbh->{AutoCommit} = 1;
  1381. }
  1382.  
  1383. $end_time=new Benchmark;
  1384. print "Time for update_of_primary_key_many_keys (256): " .
  1385.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1386.  
  1387. if ($server->small_rollback_segment())
  1388. {
  1389.   $dbh->disconnect;                # close connection
  1390.   $dbh = $server->connect();
  1391. }
  1392. if ($opt_fast && defined($server->{vacuum}))
  1393. {
  1394.   if ($opt_lock_tables)
  1395.   {
  1396.     do_query($dbh,"UNLOCK TABLES");
  1397.   }
  1398.   $server->vacuum(1,\$dbh,"bench1");
  1399.   if ($opt_lock_tables)
  1400.   {
  1401.     $sth = $dbh->do("LOCK TABLES bench1 WRITE") || die $DBI::errstr;
  1402.   }
  1403. }
  1404.  
  1405. if ($server->small_rollback_segment())
  1406. {
  1407.   $dbh->disconnect;                # close connection
  1408.   $dbh = $server->connect();
  1409. }
  1410.  
  1411. #
  1412. # Delete everything from table
  1413. #
  1414.  
  1415. print "Deleting rows from the table\n";
  1416. $loop_time=new Benchmark;
  1417. $count=0;
  1418.  
  1419. for ($i=0 ; $i < 128 ; $i++)
  1420. {
  1421.   $count++;
  1422.   $dbh->do("delete from bench1 where field_search = $i") or die $DBI::errstr;
  1423. }
  1424.  
  1425. $end_time=new Benchmark;
  1426. print "Time for delete_big_many_keys ($count): " .
  1427. timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1428.  
  1429. if ($opt_lock_tables)
  1430. {
  1431.   $sth = $dbh->do("UNLOCK TABLES") || die $DBI::errstr;
  1432. }
  1433.  
  1434. print "Deleting everything from table\n";
  1435. $count=1;
  1436. if ($opt_fast)
  1437. {
  1438.   $query= ($limits->{'truncate_table'} ? "truncate table bench1" :
  1439.          "delete from bench1");
  1440.   $dbh->do($query) or die $DBI::errstr;
  1441. }
  1442. else
  1443. {
  1444.   $dbh->do("delete from bench1 where field1 > 0") or die $DBI::errstr;
  1445. }
  1446.  
  1447. $end_time=new Benchmark;
  1448. print "Time for delete_all_many_keys ($count): " .
  1449.   timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1450.  
  1451. $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
  1452. if ($opt_fast && defined($server->{vacuum}))
  1453. {
  1454.   $server->vacuum(1,\$dbh);
  1455. }
  1456.  
  1457. #
  1458. # Test multi value inserts if the server supports it
  1459. #
  1460.  
  1461. if ($limits->{'insert_multi_value'})
  1462. {
  1463.   $query_size=$limits->{'query_size'}; # Same limit for all databases
  1464.  
  1465.   $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'});
  1466.   do_many($dbh,$server->create("bench1",
  1467.                    ["id int NOT NULL",
  1468.                 "id2 int NOT NULL",
  1469.                 "id3 int NOT NULL",
  1470.                 "dummy1 char(30)"],
  1471.                    ["primary key (id,id2)",
  1472.                    "index index_id3 (id3)"]));
  1473.  
  1474.   $loop_time=new Benchmark;
  1475.  
  1476.   if ($opt_lock_tables)
  1477.   {
  1478.     $sth = $dbh->do("LOCK TABLES bench1 write") || die $DBI::errstr;
  1479.   }
  1480.   if ($opt_fast && $server->{transactions})
  1481.   {
  1482.     $dbh->{AutoCommit} = 0;
  1483.   }
  1484.  
  1485.   print "Inserting $opt_loop_count rows with multiple values\n";
  1486.   $query="insert into bench1 values ";
  1487.   $res=$query;
  1488.   for ($i=0 ; $i < $opt_loop_count ; $i++)
  1489.   {
  1490.     my $tmp= "($i,$i,$i,'EFGHIJKLM'),";
  1491.     if (length($i)+length($res) < $query_size)
  1492.     {
  1493.       $res.= $tmp;
  1494.     }
  1495.     else
  1496.     {
  1497.       do_query($dbh,substr($res,0,length($res)-1));
  1498.       $res=$query .$tmp;
  1499.     }
  1500.   }
  1501.   do_query($dbh,substr($res,0,length($res)-1));
  1502.  
  1503.   if ($opt_lock_tables)
  1504.   {
  1505.     $sth = $dbh->do("UNLOCK TABLES ") || die $DBI::errstr;
  1506.   }
  1507.   if ($opt_fast && $server->{transactions})
  1508.   {
  1509.     $dbh->commit;
  1510.     $dbh->{AutoCommit} = 1;
  1511.   }
  1512.  
  1513.   $end_time=new Benchmark;
  1514.   print "Time for multiple_value_insert (" . ($opt_loop_count) . "): " .
  1515.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1516.  
  1517.   if ($opt_lock_tables)
  1518.   {
  1519.     $sth = $dbh->do("UNLOCK TABLES ") || die $DBI::errstr;
  1520.   }
  1521.  
  1522.   # A big table may take a while to drop
  1523.   $loop_time=new Benchmark;
  1524.   $sth = $dbh->do("drop table bench1" . $server->{'drop_attr'}) or die $DBI::errstr;
  1525.   $end_time=new Benchmark;
  1526.   print "Time for drop table(1): " .
  1527.     timestr(timediff($end_time, $loop_time),"all") . "\n\n";
  1528. }
  1529.  
  1530. ####
  1531. #### End of benchmark
  1532. ####
  1533.  
  1534. $dbh->disconnect;                # close connection
  1535.  
  1536. end_benchmark($start_time);
  1537.  
  1538. ###
  1539. ### Some help functions
  1540. ###
  1541.  
  1542.  
  1543. # Do some sample selects on direct key
  1544. # First select finds a row, the second one doesn't find.
  1545.  
  1546. sub check_select_key
  1547. {
  1548.   my ($sel_columns,$column,$check)= @_;
  1549.   my ($loop_time,$end_time,$i,$tmp_var,$tmp,$count,$row_count,$estimated);
  1550.  
  1551.   $estimated=0;
  1552.   $loop_time=new Benchmark;
  1553.   $count=0;
  1554.   for ($i=1 ; $i <= $opt_read_key_loop_count; $i++)
  1555.   {
  1556.     $count+=2;
  1557.     $tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
  1558.     $tmp=$tmpvar % ($total_rows);
  1559.     fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp")
  1560.       or die $DBI::errstr;
  1561.     $tmp+=$total_rows;
  1562.     defined($row_count=fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp")) or die $DBI::errstr;
  1563.     die "Found $row_count rows on impossible id: $tmp\n" if ($row_count);
  1564.     $end_time=new Benchmark;
  1565.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
  1566.                        $opt_loop_count));
  1567.   }
  1568.   if ($estimated)
  1569.   { print "Estimated time"; }
  1570.   else
  1571.   { print "Time"; }
  1572.   print " for $check ($count): " .
  1573.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1574. }
  1575.  
  1576. # Same as above, but select on 2 columns
  1577.  
  1578. sub check_select_key2
  1579. {
  1580.   my ($sel_columns,$column,$column2,$check)= @_;
  1581.   my ($loop_time,$end_time,$i,$tmp_var,$tmp,$count,$row_count,$estimated);
  1582.  
  1583.   $estimated=0;
  1584.   $loop_time=new Benchmark;
  1585.   $count=0;
  1586.   for ($i=1 ; $i <= $opt_read_key_loop_count; $i++)
  1587.   {
  1588.     $count+=2;
  1589.     $tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
  1590.     $tmp=$tmpvar % ($total_rows);
  1591.     fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp and $column2=$tmp")
  1592.       or die $DBI::errstr;
  1593.     $tmp+=$total_rows;
  1594.     defined($row_count=fetch_all_rows($dbh,"select $sel_columns from bench1 where $column=$tmp and $column2=$tmp")) or die $DBI::errstr;
  1595.     die "Found $row_count rows on impossible id: $tmp\n" if ($row_count);
  1596.     $end_time=new Benchmark;
  1597.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$i,
  1598.                        $opt_loop_count));
  1599.   }
  1600.   if ($estimated)
  1601.   { print "Estimated time"; }
  1602.   else
  1603.   { print "Time"; }
  1604.   print " for $check ($count): " .
  1605.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1606. }
  1607.  
  1608. #
  1609. # Search using some very simple queries
  1610. #
  1611.  
  1612. sub check_select_range
  1613. {
  1614.   my ($column,$check)= @_;
  1615.   my ($loop_time,$end_time,$i,$tmp_var,$tmp,$query,$rows,$estimated);
  1616.  
  1617.   $estimated=0;
  1618.   $loop_time=new Benchmark;
  1619.   $found=$count=0;
  1620.   for ($test=1 ; $test <= $range_loop_count; $test++)
  1621.   {
  1622.     $count+=$#Q+1;
  1623.     for ($i=0 ; $i < $#Q ; $i+=2)
  1624.     {
  1625.       $query=$Q[$i];
  1626.       $rows=$Q[$i+1];
  1627.       $query =~ s/!id!/$column/g;
  1628.       if (($row_count=fetch_all_rows($dbh,$query)) != $rows)
  1629.       {
  1630.     if ($row_count == undef())
  1631.     {
  1632.       die "Got error: $DBI::errstr when executing $query\n";
  1633.     }
  1634.     die "'$query' returned wrong number of rows: $row_count instead of $rows\n";
  1635.       }
  1636.       $found+=$row_count;
  1637.     }
  1638.     $end_time=new Benchmark;
  1639.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$test,
  1640.                        $range_loop_count));
  1641.   }
  1642.   if ($estimated)
  1643.   { print "Estimated time"; }
  1644.   else
  1645.   { print "Time"; }
  1646.   print " for $check ($count:$found): " .
  1647.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1648. }
  1649.  
  1650.  
  1651. #
  1652. # SELECT * from bench where col=x or col=x or col=x ...
  1653.  
  1654.  
  1655. sub check_or_range
  1656. {
  1657.   my ($column,$check)= @_;
  1658.   my ($loop_time,$end_time,$i,$tmp_var,$tmp,$columns,$estimated,$found,
  1659.       $or_part,$count,$loop_count);
  1660.  
  1661.   $columns=min($limits->{'max_columns'},50,($limits->{'query_size'}-50)/13);
  1662.   $columns=$columns- ($columns % 4); # Make Divisible by 4
  1663.  
  1664.   $estimated=0;
  1665.   $loop_time=new Benchmark;
  1666.   $found=0;
  1667.   # The number of tests must be divisible by the following
  1668.   $tmp= $limits->{'func_extra_in_num'} ? 15 : 10; 
  1669.   # We need to calculate the exact number of test to make 'Estimated' right
  1670.   $loop_count=$range_loop_count*10+$tmp-1;
  1671.   $loop_count=$loop_count- ($loop_count % $tmp);
  1672.   
  1673.   for ($count=0 ; $count < $loop_count ; )
  1674.   {
  1675.     for ($rowcnt=0; $rowcnt <= $columns; $rowcnt+= $columns/4)
  1676.     {
  1677.       my $query="select * from bench1 where ";
  1678.       my $or_part= "$column = 1";
  1679.       $count+=2;
  1680.  
  1681.       for ($i=1 ; $i < $rowcnt ; $i++)
  1682.       {
  1683.     $tmpvar^= ((($tmpvar + 63) + $i)*3 % $opt_loop_count);
  1684.     $tmp=$tmpvar % ($opt_loop_count*4);
  1685.     $or_part.=" or $column=$tmp";
  1686.       }
  1687.       print $query . $or_part . "\n" if ($opt_debug);
  1688.       ($rows=fetch_all_rows($dbh,$query . $or_part)) or die $DBI::errstr;
  1689.       $found+=$rows;
  1690.  
  1691.       if ($limits->{'func_extra_in_num'})
  1692.       {
  1693.     my $in_part=$or_part;    # Same query, but use 'func_extra_in_num' instead.
  1694.     $in_part=~ s/ = / IN \(/;
  1695.     $in_part=~ s/ or $column=/,/g;
  1696.     $in_part.= ")";
  1697.     fetch_all_rows($dbh,$query . $in_part) or die $DBI::errstr;
  1698.     $count++;
  1699.       }
  1700.       # Do it a little harder by setting a extra range
  1701.       defined(($rows=fetch_all_rows($dbh,"$query($or_part) and $column < 10"))) or die $DBI::errstr;
  1702.       $found+=$rows;
  1703.     }
  1704.     $end_time=new Benchmark;
  1705.     last if ($estimated=predict_query_time($loop_time,$end_time,\$count,$count,
  1706.                        $loop_count));
  1707.   }
  1708.  
  1709.   if ($estimated)
  1710.   { print "Estimated time"; }
  1711.   else
  1712.   { print "Time"; }
  1713.   print " for $check ($count:$found): " .
  1714.     timestr(timediff($end_time, $loop_time),"all") . "\n";
  1715. }
  1716.  
  1717. #
  1718. # General test of SELECT ... WHERE id in(value-list)
  1719. #
  1720.  
  1721. sub test_where_in
  1722. {
  1723.   my ($t1,$t2,$id,$from,$to)= @_;
  1724.  
  1725.   return if ($from >= $to);
  1726.  
  1727.   $query="SELECT $t1.* FROM $t1 WHERE $id IN (";
  1728.   for ($i=1 ; $i <= $to ; $i++)
  1729.   {
  1730.     $query.="$i,";
  1731.   }
  1732.   $query=substr($query,0,length($query)-1) . ")";
  1733.  
  1734.   # Fill join table to have the same id's as 'query'
  1735.   for ($i= $from ; $i <= $to ; $i++)
  1736.   {
  1737.     $dbh->do("insert into $t2 values($i)") or die $DBI::errstr;
  1738.   }
  1739.   if ($opt_fast && defined($server->{vacuum}))
  1740.   {
  1741.     $server->vacuum(1,\$dbh,"bench1");
  1742.   }
  1743.  
  1744.   time_fetch_all_rows("Testing SELECT ... WHERE id in ($to values)",
  1745.               "select_in", $query, $dbh,
  1746.               $range_loop_count);
  1747.   time_fetch_all_rows(undef, "select_join_in",
  1748.               "SELECT $t1.* FROM $t2 left outer join $t1 on ($t1.$id=$t2.$id)",
  1749.                $dbh, $range_loop_count);
  1750. }
  1751.